package org.jeecg.modules.logistics.dictionaries.cl_dic.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.modules.logistics.dictionaries.cl_dic.entity.ClDicInfo;
import org.jeecg.modules.logistics.dictionaries.cl_dic.mapper.ClDicMapper;
import org.jeecg.modules.logistics.dictionaries.cl_dic.service.IClDicService;
import org.jeecg.modules.logistics.table.clcc.entity.Clcc;
import org.jeecg.modules.logistics.table.clcpys.entity.Clcpys;
import org.jeecg.modules.logistics.table.cllx.entity.Cllx;
import org.jeecg.modules.logistics.table.clpp.entity.Clpp;
import org.jeecg.modules.logistics.table.clzz.entity.Clzz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2019/12/24  10:55
 */
@Service
@DS("freight")
public class ClDicServiceImpl implements IClDicService {
    @Autowired
    ClDicMapper clDicMapper;

    @Override
    public ClDicInfo getClDicInfo() {
        ClDicInfo clDicInfo = new ClDicInfo();
        clDicInfo.setClccList(clDicMapper.getAllClcc());
        clDicInfo.setClcpysList(clDicMapper.getAllClcpys());
        clDicInfo.setCllxList(clDicMapper.getAllCllx());
        clDicInfo.setClppList(clDicMapper.getAllClpp());
        clDicInfo.setClzzList(clDicMapper.getAllClzz());
        return clDicInfo;
    }

    //TODO clcc 车辆车长
    //TODO clcpys 车辆车牌颜色
    //TODO cllx 车辆类型
    //TODO clpp 车辆品牌
    //TODO clzz 车辆载重
    @Override
    public int putClDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "clcc":
                Clcc clcc = (Clcc) jsonObj.get("data");
                return clDicMapper.PutClcc(clcc);
            case "clcpys":
                Clcpys clcpys = (Clcpys) jsonObj.get("data");
                return clDicMapper.PutClcpys(clcpys);
            case "cllx":
                Cllx cllx = (Cllx) jsonObj.get("data");
                return clDicMapper.PutCllx(cllx);
            case "clpp":
                Clpp clpp = (Clpp) jsonObj.get("data");
                return clDicMapper.PutClpp(clpp);
            case "clzz":
                Clzz clzz = (Clzz) jsonObj.get("data");
                return clDicMapper.PutClzz(clzz);
            default:
                return 0;
        }
    }

    @Override
    public int delClDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        int id = jsonObj.getInt("data");
        switch (dic) {
            case "clcc":
                return clDicMapper.DelClcc(id);
            case "clcpys":
                return clDicMapper.DelClcpys(id);
            case "cllx":
                return clDicMapper.DelCllx(id);
            case "clpp":
                return  clDicMapper.DelClpp(id);
            case "clzz":
                return clDicMapper.DelClzz(id);
            default:
                return 0;
        }
    }

    @Override
    public int addClDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "clcc":
                Cllx clcc = (Cllx) jsonObj.get("data");
                return clDicMapper.AddClcc(clcc);
            case "clcpys":
                Clcpys clcpys = (Clcpys) jsonObj.get("data");
                return clDicMapper.AddClcpys(clcpys);
            case "cllx":
                Cllx cllx = (Cllx) jsonObj.get("data");
                return clDicMapper.AddCllx(cllx);
            case "clpp":
                Clpp clpp = (Clpp) jsonObj.get("data");
                return clDicMapper.AddClpp(clpp);
            case "clzz":
                Clzz clzz = (Clzz) jsonObj.get("data");
                return clDicMapper.AddClzz(clzz);
            default:
                return 0;
        }
    }
}
